/* components */
import PlanTaskEditForm from '@src/modules/task/taskTypes/allot/components/PlanTaskEditForm/PlanTaskEditForm.vue'
import AllotMapDialog from '@src/modules/task/taskTypes/allot/components/AllotMapDialog/AllotMapDialog.tsx'
import BatchAllotDialog from '@src/modules/task/taskTypes/allot/components/BatchAllotDialog/BatchAllotDialog.tsx'
import TaskAllotModal from '@src/modules/task/components/TaskAllotModal/TaskAllotModal.tsx'
import PropagandaPage from '@src/component/compomentV2/PropagandaPage';
/* enum */
import ComponentNameEnum from '@model/enum/ComponentNameEnum'
/* render */
import TaskAllotListRender from '@src/modules/task/taskTypes/allot/TaskAllotListRender.tsx'
/* scss */
import '@src/modules/task/taskTypes/allot/TaskAllotList.scss'
import '@src/modules/task/components/TaskAllotModal/TaskMapInfoWindow/TaskMapInfoWindow.scss'
/* vue */
import { Component } from 'vue-property-decorator'
import { CreateElement } from 'vue'
import * as _ from 'lodash';

@Component({ 
  name: ComponentNameEnum.TaskAllotList,
  components: {
    [PlanTaskEditForm.name]: PlanTaskEditForm,
    [ComponentNameEnum.AllotMapDialog]: AllotMapDialog,
    [ComponentNameEnum.BatchAllotDialog]: BatchAllotDialog,
    [TaskAllotModal.name]: TaskAllotModal,
    [PropagandaPage.name]: PropagandaPage,
  }
})
export default class TaskAllotList extends TaskAllotListRender {
  async mounted() {
    // 恢复常用
    this.recoverCommonUse();
    // 获取初始化数据
    await this.fetchInitData()
    // 获取指派工单列表
    this.search()
    // 初始化工单字段列表
    this.initializeTaskTypeAllFields()
    // [tab_spec]标准化刷新方式
    window.__exports__refresh = async () => {
      setTimeout(() => {
        this.search()
      }, 1000)
    }
    let that_ = this;
    // 监听切换后需要重新计算列表高度 后续可以用activated生命周期替换
    window.addEventListener('message', (event:any)=> {
      const {action, data} = event.data;
      if (action == 'shb.frame.activatedPage'){
        that_.$nextTick(()=> {
          that_.knowTableContainerHeight();
        })
      }
    });
    this.$nextTick(()=> {
      this.knowTableContainerHeight()
      window.onresize = _.debounce(()=>{
        that_.knowTableContainerHeight()
      }, 500)
    })
    
  }
  
  render(h: CreateElement) {
    // 属性列表
    const attrs = this.getAttributes()
    
    return (
      <div {...attrs}>
        { this.renderHeaderContainer() }
        <div v-show={!this.mapShow}>
          { this.renderOperationContainer() }
          { this.renderContentContainer() }
        </div>
        { this.renderComponentsContainer() }
      </div>
    )
    
  }
  
}

